package de.openlaboratory.elib.utilities;

import javax.servlet.http.HttpServletRequest;

import de.openlaboratory.elib.core.LogManager;

public class ServletUtils
{

	public static String getPath(HttpServletRequest request)
	{
		String path = request.getPathInfo();
		int pos = path.lastIndexOf("/");
		
		LogManager.logMessage("Servlet path: " + path + " (" + path.substring(pos) + ")");
		
		return path.substring(0, pos);
	}
	
	public static String getPage(HttpServletRequest request)
	{
		String path = request.getPathInfo();
		String[] dirs = null;
		
		LogManager.logMessage("Servlet path: " + path);
		
		if(path != null)
		{
			dirs = path.trim().split("/");
		}
		
		if(dirs != null && dirs.length > 1)
			return dirs[dirs.length - 1];
		else
			return "/";
	}
}
